#encoding:utf-8

import unittest
from hero import *
from equip import *
from item import *

class TestExpLevelItem(unittest.TestCase):
    
    def test_expLevel(self):
        player1 = Hero(name=u"狄洛",vitality=20,power=20,strength=20,intellect=10,speed=10,exp=10000)     #初始化得到10000经验
        self.assertEqual(player1.level, 8)          #当前等级
        self.assertEqual(player1.exp, 1229)         #当前经验
        self.assertEqual(player1.maxexp, 6561)      #下一级升级经验
        self.assertEqual(player1.maxPoint, 35)      #总升级属性点
        self.assertEqual(player1.pointed, 0)        #已用属性点
        self.assertEqual(player1.lavePoint, 35)     #剩余属性点
        
        player1.attributePoint(vitality=8,power=10,strength=6,speed=6,intellect=3)      #加属性点
        self.assertEqual(player1.maxhp, 523)
        self.assertEqual(player1.maxmp,352)
        self.assertEqual(int(player1.atk),82)
        self.assertEqual(int(player1.defend),71)
        self.assertEqual(int(player1.dexterity),55)
        self.assertEqual(int(player1.magic),45)
        
        self.assertEqual(player1.maxPoint, 35)      #总升级属性点
        self.assertEqual(player1.pointed, 33)       #已用属性点
        self.assertEqual(player1.lavePoint, 2)      #剩余属性点
        
        player1.exp = 7000                          #得到7000经验
        self.assertEqual(player1.level, 9)          #当前等级
        self.assertEqual(player1.exp, 1668)         #当前等级
        self.assertEqual(player1.maxexp, 10000)     #下一级升级经验
        self.assertEqual(player1.maxPoint, 40)      #总升级属性点
        self.assertEqual(player1.pointed, 33)       #已用属性点
        self.assertEqual(player1.lavePoint, 7)      #剩余属性点
    
    def test_item(self):
        player1 = Hero(name=u"狄洛",vitality=20,power=20,strength=20,intellect=10,speed=10)
        self.assertEqual(player1.hp, 400)
        player1.hp = player1.hp - 300
        player1.item(Item(hp=150))                      #吃小生命药水(hp+150)
        self.assertEqual(player1.hp, 250)
        player1.item(Item(hp=300))                      #吃中生命药水(hp+300),超过最大hp返回maxhp
        self.assertEqual(player1.hp, 400)
        
        #player1.condition = 1
        player1.condition.add(1)                        #中毒
        player1.condition.add(1)
        self.assertEqual(player1.condition, set([1]))
        player1.item(Item(condition=1))                 #解毒药
        self.assertEqual(player1.condition, set([]))
        player1.condition.add(1)                        #中毒
        player1.condition.add(2)                        #混乱
        self.assertEqual(player1.condition, set([1,2]))
        player1.item(Item(condition=1))                 #解毒药
        self.assertEqual(player1.condition, set([2]))
        player1.condition.add(3)                        #石化
        self.assertEqual(player1.condition, set([2,3]))
        player1.item(Item(condition=0))                 #万能药
        self.assertEqual(player1.condition, set([]))
        
        player2 = Hero(name=u"拉拉",vitality=20,power=20,strength=20,intellect=10,speed=10)       
        player1.hp = player1.hp - 100
        player2.hp = player2.hp - 350
        player1.item(item=Item(hp=150), obj=player2)            #狄洛给拉拉吃小生命药水
        self.assertEqual(player2.hp, 200)
        self.assertEqual(player1.hp, 300)
        

if __name__ == '__main__':
    unittest.main()
